package com.news.model;

public class CreatePage {
    private int currentP;
    private int allP;
    private int allR;
    private int perP;
    private String pageLink;
    private String pageInfo;

    public int getCurrentP() {
        return currentP;
    }

    public int getAllR() {
        return allR;
    }

    public void setAllR(int allR) {
        this.allR = allR;
    }

    public void setCurrentP(String strcurrentP) {
        if (strcurrentP == null || strcurrentP.equals("")) {
            strcurrentP = "1";
        }
        try {
            this.currentP = Integer.parseInt(strcurrentP);
        } catch (Exception e) {
            this.currentP = 1;
        }
        if (this.currentP <= 1) {
            this.currentP = 1;
        }
        if (this.currentP >= allP) {
            this.currentP = allP;
        }
    }

    public int getAllP() {
        return allP;
    }

    public void setAllP() {
        this.allP = (allR % perP == 0) ? (allR / perP) : (allR / perP + 1);
    }

    public int getPerP() {
        return perP;
    }

    public void setPerP(int perP) {
        this.perP = perP;
    }

    public String getPageLink() {
        return pageLink;
    }

    public void setPageLink(String gowhich) {
        if (gowhich.indexOf("?") > 0) {
            gowhich += "&";
        } else {
            gowhich += "?";
        }
        if (allP > 1) {
            this.pageLink = "<table border=0><tr><td>";
            if (currentP >= 1) {
                this.pageLink += "<a href=" + gowhich + "showpage=1" + "'>首页&nbsp;";
                this.pageLink += "<a href=" + gowhich + "showpage=" + (currentP - 1) + "'>上一页&nbsp;";
            }
            if (currentP <= allP) {
                this.pageLink += "<a href='" + gowhich + "showpage=" + (currentP + 1) + "'>下一页&nbsp;";
                this.pageLink += "<a href='" + gowhich + "showpage=" + allP + "'>尾页";
            }
            this.pageLink += "</td></tr></table>";
        }
    }

    public String getPageInfo() {
        return pageInfo;
    }

    public void setPageInfo() {
        this.pageInfo = "<table border=0><tr><td>";
        this.pageInfo += "第&nbsp;" + currentP + "&nbsp;页，共&nbsp;" + allP + "&nbsp;页";
        this.pageInfo += "</td></tr></table>";
    }
}
